package zju.zhu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import zju.zhu.model.Resource;
import zju.zhu.model.ResourceQuery;

@Controller
@RequestMapping("/resource")
public class resourceController {
	private ResourceQuery query;

	@RequestMapping(value = "/{userId}", method = RequestMethod.GET)
	public String getUserResource(@PathVariable String userId, ModelMap model) {
		List<Resource> resource = getQuery().getResourceByUserId(userId);

		model.addAttribute("userId", userId);
		model.addAttribute("resource", resource);

		return "resourceList";
	}

	public ResourceQuery getQuery() {
		return query;
	}

	@Autowired
	public void setQuery(ResourceQuery query) {
		this.query = query;
	}
}
